package kz.edu.sdu.itech.pcs.client;

import java.util.Scanner;

import kz.edu.sdu.itech.pcs.common.Message;

public class MessageToWorker extends Message {

   WorkerProtocol protocol;

   public MessageToWorker(WorkerProtocol p) {
      protocol = p;
   }

   public boolean read() {
      boolean ok = true;
      try {
         String raw = protocol.in.nextLine();
         String line = (new Scanner(raw)).findInLine(REQUEST_PATTERN);
         if (AppProps.DEBUG)
            WorkerProtocol.log.debug(String.format("read from server: %s", line));
         ok = read(line);
      } catch (Exception e) {
         e.printStackTrace();
         ok = false;
      }
      return ok;
   }

   public WorkerProtocol getProtocol() {
      return protocol;
   }

   public void setProtocol(WorkerProtocol protocol) {
      this.protocol = protocol;
   }

}
